﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/SiteLayout.cshtml";
}
<link href="@Url.Content("/Scripts/tiny_mce/themes/advanced/skins/default/ui.css")" rel="Stylesheet"
    type="text/css" />
<link href="@Url.Content("/Scripts/tiny_mce/plugins/inlinepopups/skins/clearlooks2/window.css")" rel="Stylesheet"
    type="text/css" />
<link href="@Url.Content("/Content/tabify.css")" rel="Stylesheet"
    type="text/css" />
<script type="text/javascript" src="@Url.Content("/Scripts/tiny_mce/jquery.tinymce.js")"></script>
<script type="text/javascript" src="@Url.Content("/Scripts/loadTinyMce.js")"></script>
<script type="text/javascript" src="@Url.Content("/Scripts/jquery.tabify.js")"></script>
<script type="text/javascript" src="@Url.Content("/Scripts/knockout-2.2.1.js")"></script>
<script type="text/javascript">
    $(function () {
        loadTinyMce();
    });
</script>

<script type="text/javascript">
    
    $(document).ready(function () {

        $(function () {
            var viewModel = {
                subject: ko.observable(""),
                body: ko.observable(""),
            };
            viewModel.create = function () {
                var wikiData = {
                    Subject: viewModel.subject,
                    Body: $('#txtaBody').val() == '' ? null : $('#txtaBody').val(),
                };
                $.ajax({
                    type: "POST",
                    url: "/Wiki/CreateWiki",
                    data: ko.toJSON(wikiData),
                    contentType: "application/json",
                    success: function (data) {
                        alert(data.toString());
                    },
                    error: function () {
                        alert("Failed");
                    }
                });
            };
            ko.applyBindings(viewModel);
        });
    });
    
</script>
<div>
    Subject:
    <div><input style="width: 636px" data-bind="value: subject" type="text" /></div>
    Content:
    <div><textarea id="txtaBody" data-bind="value: body" style="height: 300px; width: 600px" class="tinymce"></textarea></div>
    <div><button data-bind ="click: create">Create</button></div>
    @Html.Hidden("routeDataId",@ViewContext.RouteData.Values["id"])
</div>